<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字练习</title>
</head>
<body>
<input type="number" placeholder="请输入1-100之间的整数:">
<input type="button" value="猜一猜" onclick="f()">
<h1>结果:<span></span></h1>
<script>
    // 得到一个1-100之间的随机整数
    let x = parseInt(Math.random()*100)+1;
    //得到文本框
    let input = document.querySelector("input");
    // 得到span
    let span = document.querySelector("span");
    let count = 0;
    function f() {
        count++
        if (input.value>x){
            span.innerText = "猜大了!";
        }else if (input.value<x){
                span.innerText = "猜小了!";
        }else {
                span.innerText = "恭喜你猜对了,一共用了"+count+"次机会";
        }
    }
</script>
</body>
</html>